<?php
/*
Uploadify
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/

// Define a destination
$dir = $_POST['dir'];
$targetFolder = '../uploads/'.$dir.'/'; // Relative to the root

//$verifyToken = md5('unique_salt' . $_POST['timestamp']);

if (!empty($_FILES)) {
	$tempFile = $_FILES['Filedata']['tmp_name'];
	$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;


	
	// Validate the file type
	$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
	$fileParts = pathinfo($_FILES['Filedata']['name']);
	$mypath = date('YmdHis', time()).rand(10000, 99999);
	$targetFile = rtrim($targetPath,'/') . '/' .$mypath.'.'.$fileParts['extension'];
	//echo $fileParts['extension'];
	//$targetFile = date('YmdHis', time()).rand(10000, 99999).$fileParts['extension'];
	//
	//
	//
	$targetFile = $targetFolder.$mypath.'.'.$fileParts['extension'];
	//echo $targetFile;
	//exit;
	//
	//	
	//
	//	
	if (in_array($fileParts['extension'],$fileTypes)) {
		move_uploaded_file($tempFile,$targetFile);
		echo 'uploads/'.$dir.'/'.$mypath.'.'.$fileParts['extension'];


	} else {
		echo 'Invalid file type.';
	}
}
?>